using GraphProcessor;
using IQIGame.Onigao.Logic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay.Editors
{
    [System.Serializable, NodeMenuItem(LevelEditorConst.Execution + "/" + LevelEditorConst.EnableServiceUnit, typeof(LevelServiceGraph))]
    public class LevelServiceExecutionNode_EnableServiceUnit : LevelServiceExecutionNode
    {
        protected override ServiceExecutionType mServiceType => ServiceExecutionType.EnableServiceUnit;

        public override string name => LevelEditorConst.EnableServiceUnit;
        [Output("目标", false)] public EditorLevelServiceTargetSetter tagOrMcid;
        [InspectorName("是否开启指定服务"), Tooltip("否为关闭指定服务")] public bool enable;
        [InspectorName("服务文件")] public BaseGraph serviceGraph;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.EnableServiceUnit, "服务", nameof(serviceGraph))]
        public int service;
        [LevelServiceEditorCustomProperty(ServiceExecutionType.EnableServiceUnit, "服务单元", nameof(service))]
        public int serviceUnitIndex;

        protected override LevelServiceCustomConfig CreateConfig()
        {
            var rConfig = new LevelServiceExecutionCustom_EnableServiceUnit()
            {
                enable = this.enable,
                service = this.service,
                serviceUnitIndex = this.serviceUnitIndex
            };
            this.tagOrMcid = new EditorLevelServiceTargetSetter(x => rConfig.tagOrMcid = x);
            return rConfig;
        }

        protected override void OnSync(EditorLevelServiceExecutionConfig newConfig, LevelServiceExecutionNode tempNode)
        {
            if (tempNode is LevelServiceExecutionNode_EnableServiceUnit rNode)
            {
                this.enable = rNode.enable;
                this.service = rNode.service;
                this.serviceUnitIndex = rNode.serviceUnitIndex;
            }
            if (newConfig.customConfig is LevelServiceExecutionCustom_EnableServiceUnit rConfig)
            {
                this.SyncTarget(rConfig.tagOrMcid);
            }
        }
    }
}